package com.kele.volateTest;

import java.util.concurrent.TimeUnit;

/**
 * @author kele
 * @date 2021/10/12 17:49
 * @description
 *  volatile
 *  可见性
 *  不能保证原子性
 *  防止指令重排
 */
public class VolatileTest {
        private volatile static int num=0;

    public static void main(String[] args) {

        new  Thread(()->{
            while (num==0){

            }
        }).start();

        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        num=1;
        System.out.println(num);
    }
}
